package com.rpay.dao.user;

import com.rpay.model.user.UserTokenDO;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

/**
 * @author FangXiGang
 * @date 2018/4/21
 */
@Repository
public class UserTokenDao {

    @Autowired
    @Qualifier("writeSqlSession")
    private SqlSessionTemplate writeSqlSession;

    @Autowired
    @Qualifier("readSqlSession")
    private SqlSessionTemplate readSqlSession;

    public UserTokenDO selectByUserId(Integer userId){
        return readSqlSession.selectOne("rpay.user.token.selectUserToken", userId);
    }

    public UserTokenDO selectByRefreshToken(String refreshToken) {
        return readSqlSession.selectOne("rpay.user.token.selectByRefreshToken", refreshToken);
    }

    public UserTokenDO selectByAccessToken(String accessToken) {
        return readSqlSession.selectOne("rpay.user.token.selectByAccessToken", accessToken);
    }

    public int update(UserTokenDO userTokenDO){
        return writeSqlSession.update("rpay.user.token.update", userTokenDO);
    }

    public int insert(UserTokenDO userTokenDO) {
        return writeSqlSession.insert("rpay.user.token.insert", userTokenDO);
    }
}
